package edu.gdpu.gc;

/**
 * @author mazebin
 * @date 2021年 07月16日 19:56:52
 * G1日志分析
 * 虚拟机相关参数
 * -verbose:gc
 *  -Xms10m
 *  -Xmx10m
 *  -XX:+UseG1GC
 *  -XX:+PrintGCDetails
 *  -XX:+PrintGCDateStamps 打印收集时间
 *  -XX:MaxGCPauseMillis=200m 设置垃圾收集最大停顿时间
 */
public class G1LogAnalysis {
    public static void main(String[] args) {
        int size = 1024 * 1024;
        byte[] bytes1 = new byte[size];
        byte[] bytes2 = new byte[size];
        byte[] bytes3 = new byte[size];
        byte[] bytes4 = new byte[size];
        System.out.println("hello world");
    }
    /**
     GC日志：
     2021-07-16T20:05:36.002+0800: [GC pause (G1 Humongous Allocation) (young) (initial-mark), 0.0054106 secs]
     [Parallel Time: 4.3 ms, GC Workers: 8]
     [GC Worker Start (ms): Min: 159.1, Avg: 159.1, Max: 159.2, Diff: 0.1]
     [Ext Root Scanning (ms): Min: 0.4, Avg: 0.4, Max: 0.5, Diff: 0.2, Sum: 3.5]
     [Update RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
     [Processed Buffers: Min: 0, Avg: 0.0, Max: 0, Diff: 0, Sum: 0]
     [Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
     [Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
     [Object Copy (ms): Min: 3.6, Avg: 3.7, Max: 3.8, Diff: 0.2, Sum: 29.3]
     [Termination (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.2]
     [Termination Attempts: Min: 1, Avg: 4.3, Max: 7, Diff: 6, Sum: 34]
     [GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.3]
     [GC Worker Total (ms): Min: 4.1, Avg: 4.2, Max: 4.2, Diff: 0.1, Sum: 33.3]
     [GC Worker End (ms): Min: 163.3, Avg: 163.3, Max: 163.3, Diff: 0.0]
     [Code Root Fixup: 0.0 ms]
     [Code Root Purge: 0.0 ms]
     [Clear CT: 0.6 ms]
     [Other: 0.5 ms]
     [Choose CSet: 0.0 ms]
     [Ref Proc: 0.3 ms]
     [Ref Enq: 0.0 ms]
     [Redirty Cards: 0.1 ms]
     [Humongous Register: 0.0 ms]
     [Humongous Reclaim: 0.0 ms]
     [Free CSet: 0.0 ms]
     [Eden: 2048.0K(4096.0K)->0.0B(2048.0K) Survivors: 0.0B->1024.0K Heap: 3624.3K(10.0M)->2840.1K(10.0M)]
     [Times: user=0.00 sys=0.00, real=0.01 secs]
     2021-07-16T20:05:36.008+0800: [GC concurrent-root-region-scan-start]
     2021-07-16T20:05:36.008+0800: [GC concurrent-root-region-scan-end, 0.0004662 secs]
     2021-07-16T20:05:36.008+0800: [GC concurrent-mark-start]
     2021-07-16T20:05:36.009+0800: [GC concurrent-mark-end, 0.0000546 secs]
     2021-07-16T20:05:36.009+0800: [GC pause (G1 Humongous Allocation) (young), 0.0010790 secs]
     [Parallel Time: 0.7 ms, GC Workers: 8]
     [GC Worker Start (ms): Min: 165.4, Avg: 165.6, Max: 166.0, Diff: 0.6]
     [Ext Root Scanning (ms): Min: 0.0, Avg: 0.1, Max: 0.3, Diff: 0.3, Sum: 1.1]
     [Update RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
     [Processed Buffers: Min: 0, Avg: 0.0, Max: 0, Diff: 0, Sum: 0]
     [Scan RS (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
     [Code Root Scanning (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
     [Object Copy (ms): Min: 0.0, Avg: 0.3, Max: 0.4, Diff: 0.4, Sum: 2.4]
     [Termination (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.2]
     [Termination Attempts: Min: 1, Avg: 5.8, Max: 13, Diff: 12, Sum: 46]
     上面的几个步骤为YOUNG GC 的固定执行步骤
     阶段一：根扫描（GCRoots扫描）
     静态和本地对象被扫描
     阶段二：更新RS
     处理dirty card 队列更新RS
     阶段三：处理RS
      检测从年轻代指向老年代的对象
     阶段四：对象拷贝
     拷贝存活的对象到survivor/old区域
     阶段五：处理引用队列
     软引用，弱引用，虚引用处理
     [GC Worker Other (ms): Min: 0.0, Avg: 0.0, Max: 0.0, Diff: 0.0, Sum: 0.0]
     [GC Worker Total (ms): Min: 0.0, Avg: 0.5, Max: 0.6, Diff: 0.6, Sum: 3.7]
     [GC Worker End (ms): Min: 166.1, Avg: 166.1, Max: 166.1, Diff: 0.0]
     [Code Root Fixup: 0.0 ms]
     [Code Root Purge: 0.0 ms]
     [Clear CT: 0.1 ms]
     [Other: 0.3 ms]
     [Choose CSet: 0.0 ms]
     [Ref Proc: 0.1 ms]
     [Ref Enq: 0.0 ms]
     [Redirty Cards: 0.1 ms]
     [Humongous Register: 0.0 ms]
     [Humongous Reclaim: 0.0 ms]
     [Free CSet: 0.0 ms]
     [Eden: 1024.0K(2048.0K)->0.0B(1024.0K) Survivors: 1024.0K->1024.0K Heap: 3905.1K(10.0M)->4084.9K(10.0M)]
     [Times: user=0.00 sys=0.00, real=0.00 secs]
     2021-07-16T20:05:36.010+0800: [Full GC (Allocation Failure)  4084K->3670K(10M), 0.0022341 secs]
     [Eden: 0.0B(1024.0K)->0.0B(1024.0K) Survivors: 1024.0K->0.0B Heap: 4084.9K(10.0M)->3670.5K(10.0M)], [Metaspace: 3130K->3130K(1056768K)]
     [Times: user=0.00 sys=0.00, real=0.00 secs]
     2021-07-16T20:05:36.013+0800: [GC remark, 0.0000176 secs]
     [Times: user=0.00 sys=0.00, real=0.00 secs]
     2021-07-16T20:05:36.013+0800: [GC concurrent-mark-abort]
     hello world
     Heap
     garbage-first heap   total 10240K, used 4694K [0x00000000ff600000, 0x00000000ff700050, 0x0000000100000000)
     region size 1024K, 1 young (1024K), 0 survivors (0K)
     Metaspace       used 3227K, capacity 4496K, committed 4864K, reserved 1056768K
     class space    used 350K, capacity 388K, committed 512K, reserved 1048576K

     */

}
